//
//  ScoreAlertViewController.swift
//  KeyboardAndEmoji
//
//  Created by AP020Mac mini on 2025/9/26.
//

import UIKit

typealias ResultFinishBlock = ([String: Any]) -> Void

class ScoreAlertViewController: UIViewController {
    
    var finishBlock: ResultFinishBlock?
    private var evaluationView: ScoreAlertView!
    
    init(params: [String: Any]?) {
        super.init(nibName: nil, bundle: nil)
        self.modalPresentationStyle = .overFullScreen
        self.modalTransitionStyle = .crossDissolve
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initView()
    }
    
    private func initView() {
        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
        
        self.evaluationView = ScoreAlertView(frame: CGRect(x: 0, y: 0, width: 267, height: 266))
        self.view.addSubview(self.evaluationView)
        self.evaluationView.centerX = self.view.centerX
        self.evaluationView.centerY = self.view.centerY - 5
        
        self.evaluationView.block = { [weak self] isSubmit, rate in
            guard let self = self else { return }
            
            if isSubmit {
                // Assuming XHLogsManager is available in Swift
                // XHLogsManager.defaultManager().logEventManagement(withPageGrade: rate, pageId: "AppRating")
            }
            
            self.dismiss(animated: true) {
                var dic: [String: Any] = [:]
                dic["isSubmit"] = isSubmit
                dic["rate"] = rate
                self.finishBlock?(dic)
            }
        }
    }
}
